import { Base64 } from 'js-base64'

export const useLoginEffect = (checked, loginForm) => {
  // 初始化登录表单逻辑
  const initForm = () => {
    loginForm.username = localStorage.getItem('a_username')
      ? Base64.decode(localStorage.getItem('a_username'))
      : ''
    loginForm.password = localStorage.getItem('a_password')
      ? Base64.decode(localStorage.getItem('a_password'))
      : ''
  }
  // 记住登录表单逻辑
  const handleRemember = (data) => {
    if (checked.value) {
      localStorage.setItem('a_username', Base64.encode(data.username))
      localStorage.setItem('a_password', Base64.encode(data.password))
    } else {
      localStorage.removeItem('a_username')
      localStorage.removeItem('a_password')
    }
  }

  return { handleRemember, initForm }
}
